8 #define D(x) cout << #x " es " << x << endl
12 while (cin
>> n
&& n
){
19 vector
<int> childs
[m
];
21 for (int x
= 0, i
= 0; x
< n
; ++x
){
27 int j
= line
.find_first_of("'");
28 char delimiter
= line
[j
];
29 while (assert(j
< line
.size()), line
[++j
] != delimiter
){
34 childs
[stk
.top()].push_back(i
);
35 parent
[i
] = stk
.top();
36 //D(parent[i]), D(content[i]);
43 int p
= 0, q
= 0; //p = nodo en donde estoy, q = id de p en la lista de sus hermanos
45 cout
<< "Case " << C
++ << ":" << endl
;
53 if (s
== "first_child"){
54 if (childs
[p
].size() <= 0) valid
= false;
59 }else if (s
== "next_sibling"){
61 if (parent
[p
] < 0 || y
>= childs
[parent
[p
]].size()) valid
= false;
62 else x
= childs
[parent
[p
]][y
];
63 }else if (s
== "previous_sibling"){
65 if (parent
[p
] < 0 || y
< 0 || y
>= childs
[parent
[p
]].size()) valid
= false;
66 else x
= childs
[parent
[p
]][y
];
67 }else if (s
== "parent"){
69 if (x
< 0) valid
= false;
73 cout
<< content
[x
] << endl
;
76 else cout
<< content
[p
] << endl
;